GBML manual / Drawing

draw_sprite_3d_scaled

draw_sprite_3d at any size: xscale and yscale make the picture wider and taller (or smaller) the way they do in draw_sprite_scaled, and the curve grows with it, so a depth means the same thing at any size. shape and depth work exactly as they do in draw_sprite_3d. A negative xscale or yscale flips the whole picture, curve and all (a yscale of -1 is a reflection).

Works differently on Game Boy - The Game Boy narrows the picture on some lines by moving its two sprite pieces toward each other (the middle is covered, not squeezed), a drum or a band hides it outside the lens; 16 pixels wide at most, one picture at a time; the size is not used.

Works differently on Game Boy Color - The Game Boy Color narrows the picture on some lines by moving its two sprite pieces toward each other (the middle is covered, not squeezed), a drum or a band hides it outside the lens; 16 pixels wide at most, one picture at a time; the size is not used.

Sega Genesis: not available

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

draw_sprite_3d_scaled(spr, x, y, frame, shape, depth, xscale, yscale)

Arguments

NameType
sprsprite
xreal
yreal
frameint
shapesprite_shape
depthint
xscalereal
yscalereal

Returns

Nothing.

Description

draw_sprite_3d at any size. The picture curves away from you like it is wrapped round a barrel or tipped back like a sign, and xscale and yscale make it wider or narrower and taller or shorter, the way they do in draw_sprite_scaled. A boss that swells as it arrives, a logo that pops in, a picture on a sign that is bigger than its art.

A real capture - the same striped lighthouse drawn with SPRITE_BULGE at depth 3 at half its size, and at one and a half times its size, then twice as wide as it is tall. The curve has the same shape at every sizeA real capture - the same striped lighthouse drawn with SPRITE_BULGE at depth 3 at half its size, and at one and a half times its size, then twice as wide as it is tall. The curve has the same shape at every size
A real capture - the same striped lighthouse drawn with SPRITE_BULGE at depth 3 at half its size, and at one and a half times its size, then twice as wide as it is tall. The curve has the same shape at every size

The same call with different sizes: 0.5, 1.5, and twice as wide as tall. Real pictures from a Game Boy Advance ROM, cut out and put side by side (the console can do only two 3D things at once, so they are different moments). A tall striped lighthouse stands in for the example's spr_doc_tower.

The first six numbers are draw_sprite_3d's own: the sprite, (x, y), the frame, the shape (SPRITE_BULGE, SPRITE_LEAN_BACK, SPRITE_LEAN_FORWARD or SPRITE_DRUM) and the depth (0 to 3, and 1 to 6 for the drum). The last two are the scale. Everything about what they do is the same as for draw_sprite_scaled with no angle and no flips:

With a scale of 1 and 1, the picture is exactly what draw_sprite_3d draws.

The curve grows with the sprite

depth is a share of the width the far edge keeps, not a number of pixels. Drawn twice as big, the picture has a curve twice as long and exactly the same shape, so depth 3 means the same at every size. You never have to work out a new depth for a new size.

A real capture, 16 frames played in a loop - a striped lighthouse drawn with SPRITE_BULGE at depth 3 grows from half its size to one and a half times its size, then settles back to normal. The curve keeps the same shape the whole time. The first frame, which is all a viewer that cannot animate shows, is the tower at its normal size.A real capture, 16 frames played in a loop - a striped lighthouse drawn with SPRITE_BULGE at depth 3 grows from half its size to one and a half times its size, then settles back to normal. The curve keeps the same shape the whole time. The first frame, which is all a viewer that cannot animate shows, is the tower at its normal size.
A real capture, 16 frames played in a loop - a striped lighthouse drawn with SPRITE_BULGE at depth 3 grows from half its size to one and a half times its size, then settles back to normal. The curve keeps the same shape the whole time. The first frame, which is all a viewer that cannot animate shows, is the tower at its normal size.

The same call with the scale changing every frame (16 pictures, two frames apart, played at about half the speed of the console): the tower grows to 1.5 times its size and settles. A viewer that does not animate shows the first frame.

Flipping it

A negative xscale or yscale flips the whole picture, and the curve is flipped with it, as a mirror does. A sprite that leans back (the top shrinks away) and the same sprite with a yscale of -1 is a picture and its reflection.

A real capture - two striped lighthouses, both SPRITE_LEAN_BACK at depth 3. The one on the left is drawn the right way up and is narrow at the top. The one on the right is drawn with a yscale of -1, so it is upside down and narrow at the bottom, like a reflectionA real capture - two striped lighthouses, both SPRITE_LEAN_BACK at depth 3. The one on the left is drawn the right way up and is narrow at the top. The one on the right is drawn with a yscale of -1, so it is upside down and narrow at the bottom, like a reflection
A real capture - two striped lighthouses, both SPRITELEANBACK at depth 3. The one on the left is drawn the right way up and is narrow at the top. The one on the right is drawn with a yscale of -1, so it is upside down and narrow at the bottom, like a reflection

Two calls: a lean back with a yscale of 1, and the same with a yscale of -1. The flipped one is narrow at the bottom, because the curve was turned upside down with the picture.

SPRITE_LEAN_BACK with a yscale of -1 looks like a SPRITE_LEAN_FORWARD turned upside down.

How big can it get

The Game Boy Advance draws a stretched sprite only inside a box twice as wide and twice as tall as the sprite, and anything outside the box is cut off. So a sprite can be drawn up to 2 times its size and be whole, and past 2 times the edges of the picture are cut off. This is the rule draw_sprite_scaled has too. Making a sprite smaller never cuts anything. (A 64 pixel sprite at 2 times is 128 pixels tall, most of the 160 pixel screen.)

What it costs

The same as draw_sprite_3d, and out of the same pool: one matrix (the one the scale needs, shared with the curve and not a second), two of the 8 row-by-row effects and 640 bytes of memory, for as long as the call keeps being made. A room change keeps two of the eight, so three 3D things at once fit (a 3D sprite and a 3D text count the same). Ask for more and the game stops in a development build with a message naming every call that holds a slot, and a release build draws the extra sprite flat, at the size you asked for.

Example

draw_sprite_3d_scaled(spr_doc_tower, x, y, 0, SPRITE_BULGE, 3, 1.5, 1.5);

The tower, one and a half times its normal size, bulging like a barrel.

draw_sprite_3d_scaled(spr_doc_tower, x - 40, y, 0, SPRITE_LEAN_BACK, 3, 1, 1);
draw_sprite_3d_scaled(spr_doc_tower, x + 40, y, 0, SPRITE_LEAN_BACK, 3, 1, -1);

A tower that leans back and, beside it, the same tower upside down. Two 3D sprites at once is all the console has room for.

var size = wave(0.5, 1.5, 90, 0);
draw_sprite_3d_scaled(spr_doc_tower, x, y, 0, SPRITE_BULGE, 3, size, size);

A tower that breathes between half and one and a half times its size, once every 90 frames, curved all the time.

On the GBA

Costs what draw_sprite_3d costs - one matrix (the one the scale needs, not a second), two of the eight row-by-row effects and 640 bytes of memory - out of the same pool. depth is a proportion, not a number of pixels. A scale of exactly 1 and 1 draws what draw_sprite_3d draws, row for row. A negative scale mirrors the whole picture, curve included, so SPRITE_LEAN_BACK drawn with a yscale of -1 is a SPRITE_LEAN_FORWARD upside down; 0 still has no sign to flip by, so it reads as the smallest size (0.01). The console draws a scaled sprite inside a box twice its size, so past 2 times bigger the edges of the picture are cut off (draw_sprite_scaled’s rule). The sprite is not turned: there is no angle.

See also: draw_sprite_3ddraw_sprite_scaleddraw_text_3d_scaleddraw_sprite_ripple